for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
/*eslint no-undef: 0*/
import { get, isString, isUndefined } from 'lodash';
import { debug } from './log';
if (isUndefined(STORAGE_PREFIX)) {
STORAGE_PREFIX
/** global: STORAGE_PREFIX */
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.
throw new Error('STORAGE_PREFIX must be set.');
}
/**
*
* @param {string} key
*/
export function getStorageItem(key) {
const [root, ...rest] = key.split('.');
const item = localStorage.getItem(buildStorageKey(root));
localStorage
/** global: localStorage */
const value = isJson(item) ? JSON.parse(item) : item;
return rest.length ? get(value, rest.join('.')) : value;
* @param {*} value
export function setStorageItem(key, value) {
if (!isString(value)) {
value = JSON.stringify(value);
localStorage.setItem(buildStorageKey(key), value);
debug('storage item set: %s -> %s', key, value);
export function removeStorageItem(key) {
localStorage.removeItem(buildStorageKey(key));
debug('storage item removed: %s', key);
* @returns {string}
function buildStorageKey(key) {
return [STORAGE_PREFIX, key].join('.');
* @returns {boolean}
function isJson(value) {
try {
JSON.parse(value);
} catch (e) {
return false;
return true;
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.